package scalapackage.testfanxing

/**
  * Created by Germmy on 2018/4/14.
  */
//class UpperBoundDemo[T <: Comparable[T]] (val m1:T,val m2:T){//构造方法要不要用？
//  def select(): T ={
//    if(m1.compareTo(m2)>0) m1 else  m2
//  }
//}

class UpperBoundDemo[T <: Comparable[T]] {//构造方法要不要用,但是Comparable后面必须要加T
  def select(m1:T,m2:T): T ={
    if(m1.compareTo(m2)>0) m1 else  m2
  }
}


object UpperBoundDemo {
  def main(args: Array[String]) {

    val u=new UpperBoundDemo[MissRight]
    val m1=new MissRight("biaozi",120)
    val m2=new MissRight("erdiao",999)
    val res=u.select(m1,m2)
    println(res.name)

//    val m1=new MissRight("biaozi",1200)
//    val m2=new MissRight("erdiao",999)
//    val u=new UpperBoundDemo[MissRight](m1,m2)
//    val res=u.select
//    println(res.name)

  }
}

class MissRight(val name: String, val faceValue: Int) extends Comparable[MissRight] {//必须定义为val时，才被识别为类的属性
  //这地方入参不能是T，T必须是在源中的
  override def compareTo(o: MissRight): Int = {
    this.faceValue - o.faceValue
  }
}